﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Reflection;
using DevExpress.XtraGrid.Demos.util;
using mendian;
using Luna小店.DTO;
using Luna小店.UC.面料库存.面料出库.service;
using Luna小店.UC.面料库存.面料出库.model;
using Luna小店.UC.面料库存.订单领料出库;

namespace Luna小店.UC.面料库存
{
    public partial class Form面料出库单 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        private String code;
        private string orderTypeId;
        private string orderCustomerTypeId;
        private string id;
        private string billNo;
        private string orderTypeName;
        private string orderCustomerTypeName;
        private DTO订单领料出库明细总览 DTO订单领料出库明细总览;
        private DTO订单出库记录员工 DTO订单出库记录员工 = new DTO订单出库记录员工();

        public Form面料出库单(
            String code,   //项目成果管理的项目的code
            string id,
            String billNo,
            string orderTypeId, 
            string orderCustomerTypeId,
            string orderTypeName,
            string orderCustomerTypeName
            )
        {
            InitializeComponent();
            this.code = code;
            this.id = id;
            this.orderTypeId = orderTypeId;
            this.orderCustomerTypeId = orderCustomerTypeId;
            this.billNo = billNo;
            this.orderCustomerTypeName = orderCustomerTypeName;
            this.orderTypeName = orderTypeName;

            this.textEdit出库单号.Text = this.billNo;
            this.textEdit客户名称.Text = this.orderCustomerTypeName;
            this.textEdit订单类型.Text = this.orderTypeName;
            重新查询();
        }
        private void barButtonItem确认出库_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (String.IsNullOrEmpty(this.code))
            {
                //调用webSercice的post传值
                //原来的接口
                //StockOutService.post确认出库(this.id, this.DTO订单领料出库明细总览.orderDetails);
                //MessageBox.Show("领料出库成功");
                //this.Close();
            }
            else
            {
                this.DTO订单出库记录员工.code = this.code;
                this.DTO订单出库记录员工.id = this.id;
                this.DTO订单出库记录员工.orderDetails = FunctionHelper.JsonSerialization(this.DTO订单领料出库明细总览.orderDetails);
                new Form面料审核提交(this.DTO订单出库记录员工).ShowDialog();
            }
        }
        private void toolStripMenuItem更改出库数_Click(object sender, EventArgs e)
        {
            string orderId = FunctionHelper.GetgridViewValue(
                this.gridView出库申请,
                this.gridView出库申请.FocusedRowHandle,
                "orderId"
                );
            //弹出新form
            DTO订单领料出库单 DTO订单领料出库单 = this.DTO订单领料出库明细总览.orderDetails[this.gridView出库申请.FocusedRowHandle];
            Form面料出库单异常 form = new Form面料出库单异常(orderId,DTO订单领料出库单.异常调整);
            form.ShowDialog();
            重新查询();
        }

        private void 重新查询()
        {
            this.DTO订单领料出库明细总览 =
                //  数据清洗，计算调整值
                new StockOutModel().build(
                    //  调用webservice取值
                    StockOutService.get订单领料出库明细总览(this.orderTypeId, this.orderCustomerTypeId)
                ).DTO订单领料出库明细总览;

            this.gridControl出库申请.DataSource = this.DTO订单领料出库明细总览.orderDetails;
            this.gridControl出库分录.DataSource = this.DTO订单领料出库明细总览.summaries;
        }
    }


    
}